﻿using NHibernate;
using NHibernate.Cfg;

namespace Insesoft.DataObjects
{
    public static class NHibernateHelper
    {
        private static ISessionFactory sessionFactory;

        private static ISessionFactory SessionFactory
        {
            get { return sessionFactory ?? (sessionFactory = CreateSessionFactory()); }
        }

        public static ISession GetSession()
        {
            return SessionFactory.OpenSession();
        }

        public static void Initialize()
        {
            CreateSessionFactory();
        }
        
        private static ISessionFactory CreateSessionFactory()
        {
            var configuration = new Configuration();
            configuration.Configure();
            return configuration.BuildSessionFactory();
        }
    }

}
